package com.itheima.interceptor;

import com.itheima.controller.result.Result;
import com.itheima.system.BussinessException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: springmvc_ssm
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-04 11:41
 **/
@Component
@ControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler({BussinessException.class})
    @ResponseBody
    public Result bussiness(BussinessException e) {
        //异常也要统一格式
        System.out.println(e);
        return new Result(e.getCode(), e.getMessage());
    }
}
